#include <stdio.h>
#include <unistd.h>

int g_count = 0;

int main()
{
	pid_t pid = getpid();
	pid_t ppid = getppid();
	pid_t uid = getuid();
	pid_t euid = geteuid();
	pid_t gid = getgid();
	pid_t egid = getegid();
	
	printf("current process id is %u\n", pid);
	printf("parent process id is %u\n", ppid);
	printf("current process user id is %u\n", uid);
	printf("current process effective user id is %u\n", euid);
	printf("current process group id is %u\n", gid);
	printf("current process effective group id is %u\n", egid);

	int nStack = 1;
	int *pnHeap = (int *)malloc(sizeof(int));
	*pnHeap = 2;
	
	
	pid_t cpid = fork();
	
	if(cpid < 0) 
	{
		printf("fork error\n");
		exit(1);
	} 
	else if(cpid == 0) 
	{
		printf("This is child process, pid is %u\n", getpid());	
		g_count ++;
		nStack ++;
		(*pnHeap) ++;
		printf("child: g_count is %d, nStack is %d, *pnHeap is %d\n", g_count, nStack, *pnHeap);	
	}
	else
	{
		printf("This is parent process, pid is %u\, child process is %u\n", getpid(), cpid);	
		sleep(2);
		printf("parent: g_count is %d, nStack is %d, *pnHeap is %d\n", g_count, nStack, *pnHeap);	
	}
	return 0;
}